package com.example.readis;

import com.alibaba.fastjson2.JSON;
import com.example.home.BRespond;
import com.example.home.StringEmpty;
import com.example.pojo.BatPojoUser;
import com.fasterxml.jackson.core.JsonParser;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Mapper;
import org.apache.tomcat.util.json.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Mapper
@RestController
@RequestMapping("redis/")
public class RedisController {
    @Autowired
    private  RedisUtil util;
    @PostMapping("set")
    public Object redis_set(String key,Object object){
        return BRespond.respond_success(util.set(key,object));
    }
    @PostMapping("get")
    public Object redis_get(String key){
        return BRespond.respond_success(util.get(key));
    }
    @PostMapping("delete")
    public  Object redis_delete(String key){
        return BRespond.respond_success(util.delete(key));
    }
    @PostMapping("user_set")
    public  Object redis_user_set(BatPojoUser user){
        String key = String.valueOf(user.getId());
        if (StringEmpty.isNULL(key)){
            return BRespond.respond_failure_message(205,"id 不能为空");
        }
        return BRespond.respond_success(util.set(key,JSON.toJSONString(user)));
    }
    @PostMapping("user_get")
    public  Object redis_user_get(String id){
        return BRespond.respond_success(util.get(id));
    }
}
